package com.example.practice.controller;

import com.example.practice.entity.JsonResponse;
import com.example.practice.entity.User;
import com.example.practice.entity.respMsg;
import com.example.practice.entity.userRole;
import com.example.practice.service.UserService;
import com.example.practice.utls.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2023-12-20 21:32:41
 */
@RestController
@RequestMapping("/api/user")
@Api(tags = "UserController")
public class UserController {
    @Resource
    UserService userService;
    @ApiOperation("查询User信息")
    @GetMapping("/getUserByAccount")
    public User getUserByAccount(String account){
        return this.userService.getUserByAccount(account);
    }

    @ApiOperation("查看所有用户信息")
    @GetMapping("/getAllUser")
    public List<User> getAllUser(){
        return this.userService.getAllUser();
    }
    @ApiOperation("更改用户信息")
    @PostMapping("updateUser")
    public JsonResponse updateUser(@RequestBody User user){
         Integer I=this.userService.updateUser(user);
             return JsonResponse.success(I);
    }

    @GetMapping("getUser")
    public JsonResponse<userRole> getUser(){
            return JsonResponse.success(SecurityUtils.getUserInfo());
    }

    @GetMapping("/getName")
    public User getName(Integer id) {
        return this.userService.getName(id);}

    @ApiOperation("获取要审查的学生")
    @GetMapping("/getCheckStudent")
    public List<User> getCheckStudent(Integer uid){
        return this.userService.getCheckStudent(uid);
    }
    @GetMapping("/getByFid")
    public User getByFid(Integer fid) {
        return this.userService.getByFid(fid);}

    @GetMapping("/getByUid")
    public String getByUid(Integer uid) {
        return this.userService.getByUid(uid);}

    @GetMapping("/getDistName")
    public List<User> getDistName() {
        return this.userService.getDistName();}

    @ApiOperation("查看某个活动参加人员")
    @GetMapping("/getUserByActivity")
    public List<User> getUserByActivity(Integer aid){
        return this.userService.getUserByActivity(aid);
    }

    @ApiOperation("插入学生选择的学校")
    @GetMapping("insertStudentSchool")
    public Integer insertStudentSchool(Integer uid,Integer aid,String sname){return this.userService.insertStudentSchool(uid,aid,sname);}

    @ApiOperation("查询学生选择的学校")
    @GetMapping("selectStudentSchool")
    public String selectStudentSchool(Integer uid,Integer aid){return this.userService.selectStudentSchool(uid,aid);}

    @ApiOperation("删除中学")
    @GetMapping("deleteStudentSchool")
    public Integer deleteStudentSchool(Integer uid,Integer aid){return this.userService.deleteStudentSchool(uid,aid);}
    @ApiOperation("保存头像")
    @GetMapping("saveUserUrl")
    public Integer saveUserUrl(Integer uid,String url){return this.userService.saveUserUrl(uid,url);}

    @ApiOperation("查询头像")
    @GetMapping("selectUserUrl")
    public String selectUserUrl(Integer uid){return this.userService.selectUserUrl(uid);}

    @ApiOperation("插入用户")
    @PostMapping("insertUser")
    public Integer insertUser(@RequestBody List<User> users){
        return this.userService.insertUser(users);
    }

    @ApiOperation("查询该学校的所有学生和老师")
    @GetMapping("/getAllUserBySid")
    public List<User> getAllUserBySid(Integer sid){return this.userService.getAllUserBySid(sid);}
}

